

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>	/*read, write, close*/
#include <sys/types.h> 	/*open*/
#include <sys/stat.h> 	/*open*/
#include <fcntl.h>	/*open*/

int main(int argc, char *argv[]){
	int fd;
	char s[] = "Hello IO World\n";
	int nbytes;

	fd = open("./foo.txt", O_CREAT | O_RDWR, S_IRUSR); /*cria o arquivo, com permissoes de rwx e pra quem*/
	printf("fd == %d\n", fd);
	nbytes = write(fd, s, strlen(s)); /*escreve no arquivo*/

	write(1, "Surprise\n", strlen("surprise  "))/*fd == 1 eh o stdin, 2 stderr*/;
	close(fd);
	

/*	close(1);
	printf("sldkaglçhsdfg\n");*//*nao aparece, pois fechei o arquivo do terminal*/
	close(1);
	fd = open("./aha.txt", O_CREAT | O_RDWR, S_IRUSR);/*open retorna o decritor de arquivo mais baixo, portanto ele vai retornar 1*/
	fprintf(stderr, "fd now is %d\n", fd);
	printf("trying to printf\n");
	close(fd);

	return EXIT_SUCCESS;
}
